package cn.elead.chaos.remote.web.system.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.excel.ExcelUtil;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.mybatils.web.page.TableDataInfo;
import cn.elead.chaos.remote.web.system.service.IRemoteDictTypeService;
import cn.hutool.core.util.StrUtil;
import cn.elead.chaos.remote.web.system.domain.SysDictType;

/**
 * 字典类型Controller
 * 
 * @author luopeng
 * @date 2020-02-26 15:09:15
 */
@RestController
@RequestMapping("/remote/system/dict/type")
public class RemoteDictTypeController extends BaseController
{
    @Autowired
    private IRemoteDictTypeService dictTypeService;

    /**
     * 查询字典类型列表
     */
    @GetMapping("/page")
    @RequiresPermissions("system:dict:list")
    public TableDataInfo<SysDictType> page(SysDictType sysDictType) {
        return dictTypeService.page(sysDictType);
    }
    
    /**
     * 导出字典类型列表
     */
    @GetMapping("/export")
    @RequiresPermissions("system:dict:export")
    @Log(title = "字典类型", businessType = BusinessType.EXPORT)
    public String export(SysDictType sysDictType) {
        List<SysDictType> list = dictTypeService.list(sysDictType);
        ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取字典类型详细信息
     */
    @GetMapping(value = "/{dictId}") 
    @RequiresPermissions("system:dict:list")
    public SysDictType getInfo(@PathVariable("dictId") Long dictId) {
       	return dictTypeService.getInfo(dictId);
    }

    /**
     * 新增字典类型
     */
    @PostMapping
    @RequiresPermissions("system:dict:add")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    public int add(@RequestBody SysDictType sysDictType) {
    	return dictTypeService.add(sysDictType);
    }

    /**
     * 修改字典类型
     */
    @PutMapping
    @RequiresPermissions("system:dict:edit")
    @Log(title = "字典类型", businessType = BusinessType.UPDATE)
    public int edit(@RequestBody SysDictType sysDictType) {
        return dictTypeService.edit(sysDictType);
    }

    /**
     * 删除字典类型
     */
	@DeleteMapping("/{dictIds}")
    @RequiresPermissions("system:dict:remove")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
    public int remove(@PathVariable Long[] dictIds){
		String ids = StringUtils.join(dictIds, StrUtil.COMMA);
        return dictTypeService.remove(ids);
    }
	
	
	/**
	 * 获取字典选择框列表
	 */
	@GetMapping("/optionselect")
	public List<SysDictType> optionselect() {
		return dictTypeService.optionselect();
	}
}